﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using RMSoftware.Models;
//using BusinessObjects;
using Entities;

namespace RMSoftware.Controllers
{
    public class ProjectController : Controller
    {
        [HttpGet]
        public ActionResult ViewList()
        {
            ViewBag.Message = "Список текущих проектов";

            //return View((new DataManager()).Projects);
            return View((new BusinessObjects.Project()).Retrieve());
        }

        [HttpPost]
        public ActionResult Create(Project obj)
        {
            DataManager dm = new DataManager();

            obj.ProjectId = Guid.NewGuid();
            obj.OfficerId = dm.GetPerson(dm.GetPersonIdByUsername(User.Identity.Name)).PersonId;
            dm.SaveProject(obj);

            return RedirectToAction("ViewDetails", new { id = obj.ProjectId });
        }

        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }

        [HttpGet]
        public ActionResult Delete(Guid id)
        {
            (new DataManager()).DeleteProject(id);

            return RedirectToAction("ViewList");
        }

        [HttpGet]
        public ActionResult ViewDetails(Guid id)
        {
            return View(new DataManager().GetProject(id));
        }

        public ActionResult About()
        {
            return View();
        }
    }
}

//@Html.ListBoxFor(model => model.RiskId, new SelectList(ViewBag.RiskFactors, "RiskId", "Title"))

        //<div class="editor-label">
        //    @Html.LabelFor(model => model.RiskId)
        //</div>
        //<div class="editor-field">
        //    @Html.EditorFor(model => model.RiskId)
        //    @Html.ValidationMessageFor(model => model.RiskId)
        //</div>

        //<div class="editor-label">
        //    @Html.LabelFor(model => model.PersonId)
        //</div>
        //<div class="editor-field">
        //    @Html.EditorFor(model => model.PersonId)
        //    @Html.ValidationMessageFor(model => model.PersonId)
        //</div>